//----------------------------------------------------------------
#include "GameScene.h"
#include "A.h"
//----------------------------------------------------------------
GameScene::GameScene ()
:
m_pkHumanPlayer(NULL),
m_pkWorld(NULL)
{
}
//----------------------------------------------------------------
GameScene::~GameScene ()
{
}
//----------------------------------------------------------------
bool GameScene::onInit (Importer* pkImporter, Renderer* pkRenderer)
{
	pkImporter->importResources("../../res/sprite.xml");

	m_pkWorld = new World(pkRenderer);
	if (!m_pkWorld->loadWorldMap("../../res/tileset.xml", "../../res/WorldMap.xml"))
		return false;

	setCurrentMap(m_pkWorld->getWorldMap());

	//m_pkWorld->addResourceNode(ResourceList::Gold, 4, 4);
	m_pkWorld->addResourceNode(ResourceList::Gold, 5, 13);
	m_pkWorld->addResourceNode(ResourceList::Wood, 8, 8);
	
	m_pkHumanPlayer = new Player(m_pkWorld, this, pkImporter, m_pkWorld->getPathfinder());
	m_pkHumanPlayer->addBase(4,4); // no la deberia agregar porque ya hay un nodo en esa posicion
	//m_pkHumanPlayer->addBase(10,10); 
	m_pkHumanPlayer->addMiner(8,8); // no lo deberia agregar porque no hay base en esa posicion
	m_pkHumanPlayer->addMiner(4,4);

	m_pkHumanPlayer->giveMinerCommand(0, Miner::MinerActions::GoToMineGold);

	return true;
}
//----------------------------------------------------------------
bool GameScene::onUpdate (float fTimeBetweenFrames)
{
	m_pkHumanPlayer->update(fTimeBetweenFrames);

	if (m_pkInput->getKeyEventDown(DIK_1))
		m_pkHumanPlayer->giveMinerCommand(0, Miner::MinerActions::GoToMineGold);

	if (m_pkInput->getKeyEventDown(DIK_2))
		m_pkHumanPlayer->giveMinerCommand(0, Miner::MinerActions::GoToMineWood);

	return true;
}
//----------------------------------------------------------------
void GameScene::onDraw (Renderer* pkRenderer) const
{
}
//----------------------------------------------------------------
bool GameScene::onDeinit ()
{
	if (m_pkWorld)
	{
		delete m_pkWorld;
		m_pkWorld = NULL;
	}

	if (m_pkHumanPlayer)
	{
		delete m_pkHumanPlayer;
		m_pkHumanPlayer = NULL;
	}

	return true;
}
//----------------------------------------------------------------
